﻿



import Request from '../../base/request.js?t=202511041006'
import Storage from '../../base/storage.js?t=202511041006'
import { imageBaseUrl, isImageFile, dealTime, downloadfun, queryURLParams, DeleteFormFileItem, getBrowserInfo, dealmark, saveTime } from "../../base/utils.js?t=202511041006"

const Composition = (proxy) => {
    const data = reactive({
        textPopOpen: false,
        fillTextValue: null,
        pdfOpen: false,
        pdfurl: "",
        proxy: "",
        type: "",
        fileOpen: false,
        autoSaveParams: {
            countOpen: false,
            mainTimer: null,
            countdownTimer: null,
            countdown: 10,
            size: 26,
            ocountdown: 10,
            setIntervalTime: 5 * 1000 * 60
        },
        subform: {

        },
        mid:"",
        listInfo: {
            Title: null,
            UpdateTime: null,
            StartTime: null,
            EndTime: null,
            UserName: null,
            UserNo:null,
            UserNo:null,
            Manager: null,
            DepartmentName:null
        },
        totalAmount:0,
        dict: {
            0: '通用表考评',
            1: '重点工作考评',
            2: '现场检查考评',
        },
        nameList:[],
        ScoreRate:1,
        urlParams: {},
        s3Form: {
            TeamId: "",
            StartTime: "",
            EndTime: "",
            DepartmentId: "",
            Factor: "",
        },
        s4Form: {
            TeamId: "",
            StartTime: "",
            EndTime: "",
            DepartmentId: "",
            Factor: "",
        },
        checkGroup: [],
        memberGroup: [],

        cmemberGroup1: [],
        cmemberGroup2: [],
        checkFrom: {
            userName: "",
            userId: "",
            checkDate: "",
            advice: ""
        },
        previewShow: false,
        imgUrl: "",
        form: {
            plan: null,
            year: "",
            person: "",
            duty: "",
            subdept: ""

        },
        totala: 0,
        totals: 0,
        TotalScore: 0,
        ti:0,
        i: 0,
        is: 0,
        iss: 0,
        planList: [],

  
        lists: [

        ],

        activeKey: [0, 1,2],

        messageTest: "",

        formState: {
            dept: "",
            name: "",
            job: "",
            role: "",
            tel: "",
        },

        chooseFiles: [],

        deptList: [
       
        ],

        monthList: [
      
        ],

        pagination: {
            total: 0,
            loading: true,
            current: 1,
            pageSize: 10,
            showTotal: total => `总共 ${total} 项`,
            defaultPageSize: 10,
            // pageSizeOptions: ['5', '10', '15', '20'], // 可不设置使用默认
            showSizeChanger: true, // 是否显示pagesize选择
            showQuickJumper: false, // 是否显示跳转窗
        },

        uploadLock:false,
        memberList: [],

        chooseMember: {},
        
        logList: [],
        rules: {
            dept: [{ required: true, message: '请选择部门', trigger: 'change' }],
            name: [{ required: true, message: '请选择成员', trigger: 'change' }],

        },
        opType: "",
        confirmShow: false,
        delId: "",

        open: false, 

        queryParams: {
            role: "",
            dept: "",
        },
        statusList: [
            { name: '组长', code: '0' },
            { name: '组员', code: '1' },

        ],


        columns: [
            {
                title: '序号',
                dataIndex: 'index',
                key: 'index',
                align: 'center',
                width: 80,
                customRender: ({ index}) => {
                    return (params.pagination.value.current - 1) * params.pagination.value.pageSize + index + 1
                },
            },
            {
                title: '应用模块',
                dataIndex: 'a',
                key: 'a',
                align: 'center',
                customRender: function ({ text, record, index, column }) {
                    let linkBtn = h(antd.Button, { type: 'link' }, () => text)


                    return linkBtn
                }


            },
            {
                title: '考评扣分',
                dataIndex: 'b',
                key: 'b',
                align: 'center',
                customRender: function ({ text, record, index, column }) {

                    let numberInput = h(antd.InputNumber, { style: 'width:140px', placeholder: "请输入考评扣分", min: 0, max: 100 }, () => text)


                    return numberInput
                }
            },
            {
                title: '扣分缘由',
                dataIndex: 'c',
                key: 'c',
                align: 'center',
                customRender: function ({ text, record, index, column }) {
                    let textArea = h(antd.Textarea, { placeholder: "请输入扣分缘由", autoSize: { minRows: 2, maxRows: 5 } }, () => text)
                    return textArea
                }
            },

        ],
        dataSource: [],
        fileList: [],
        itemRender: (data) => {



            let uid = data.file.uid
            const text = h('div', { style: 'cursor:pointer;margin-left:10px' }, data.file.name)
            const previewBtn = h('img', { style: 'cursor:pointer;margin:0 4px;', onclick: () => { methods.btnPreview(uid, 1) }, src: "../Bussiness/img/svg/preview.svg", width: 20, height: 22 }, '预览')
            const downloadBtn = h('img', { style: 'cursor:pointer;margin:0 4px;', onclick: () => { methods.btnDownLoad(uid, 1) }, src: "../Bussiness/img/svg/download.svg", width: 20, height: 22 }, '下载')
            //const deleteBtn = h('img', { style: 'cursor:pointer;margin:0 4px;', onclick: () => { methods.btnDelete(uid, 1) }, src: "../Bussiness/img/svg/delete.svg", width: 18, height: 22 }, '删除')
            var btns = ""

            if (isImageFile(data.file.url)) {
                btns = h('div', { style: "display:flex;" }, [
                    previewBtn,
                    downloadBtn,
                    //deleteBtn
                ])
            } else {
                btns = h('div', { style: "display:flex;" }, [
                    downloadBtn,
                    //deleteBtn
                ])
            }

            return h('div', { style: 'margin-top:10px; width:100%;display:flex;justify-content:space-between' }, [
                text, btns
            ])

        },
    })
    let params = toRefs(data)

    const methods = {
        filterOption: (val, type) => {
            return `${type.value}`.includes(`${val || ''}`)
        },

        fillText: () => {
            let info = Storage.get('AccountInfo', true)
            params.lists.value[params.ti.value].NodeList
            [params.i.value].NodeList[params.is.value].NodeList
            [params.iss.value].ResultRemark = params.fillTextValue.value

            params.lists.value[params.ti.value].NodeList
            [params.i.value].NodeList[params.is.value].NodeList
            [params.iss.value].EvalutionName = `${info.UserName}(${info.UserNo})`


            let item = params.lists.value[params.ti.value].NodeList
            [params.i.value].NodeList[params.is.value].NodeList
            [params.iss.value]

            methods.tChange(item)


            params.textPopOpen.value = false

        },

        modelShow: (ti, i, is, iss, text) => {
            if (params.urlParams.value.detail == 1) {
                return 
            }
            params.ti.value = ti
            params.i.value = i
            params.is.value = is
            params.iss.value = iss
            params.fillTextValue.value = text
            if (text) {

            }
            params.textPopOpen.value = true
        },

        handleChange: (info, ee) => {
            if (!params.uploadLock.value) {


                params.uploadLock.value = true
                let formData = new FormData();
                formData.append('nfile', info.file.originFileObj)
                formData.append('uid', info.file.originFileObj.uid)
                Request({
                    url: "/download/uploadfile?Path=Performance",
                    method: 'post',
                    data: formData
                }).then(res => {

                    params.uploadLock.value = false
                    let item = params.lists.value[params.ti.value].NodeList
                    [params.i.value].NodeList[params.is.value].NodeList
                    [params.iss.value].ResultItemFileList.find(e => e.uid == res.Data[0].uid)
                    item.url = imageBaseUrl + res.Data[0].FilePath.split('../..')[1]
                    item.FileId = res.Data[0].FileId
                    item.FileName = res.Data[0].FileName

                    delete item.response
                    delete item.xhr

                    if (!params.lists.value[params.ti.value].NodeList
                    [params.i.value].NodeList[params.is.value].NodeList
                    [params.iss.value].uploadList) {
                        params.lists.value[params.ti.value].NodeList
                        [params.i.value].NodeList[params.is.value].NodeList
                        [params.iss.value].uploadList = []
                    }
                    params.lists.value[params.ti.value].NodeList
                    [params.i.value].NodeList[params.is.value].NodeList
                    [params.iss.value].uploadList.push(item)


                    if (ee) {
                        methods.tChange(ee)
                    }
                })
            }




        },
        //handleChange1: (info) => {
        //    let formData = new FormData();
        //    formData.append('nfile', info.file.originFileObj)
        //    formData.append('uid', info.file.originFileObj.uid)
        //    Request({
        //        url: "/download/uploadfile?Path=Performance",
        //        method: 'post',
        //        data: formData
        //    }).then(res => {
        //        let item = params.fileList.value.find(e => e.uid == res.Data[0].uid)
        //        item.url = imageBaseUrl + res.Data[0].FilePath.split('../..')[1]
        //        item.FileId = res.Data[0].FileId
        //    })

        //},
  
        setVisible: (value) => {
            params.previewShow.value = value;
        },
        btnPreview: (e, type) => {
            if (type) {
                let item = params.fileList.value.find(es => es.uid == e)
                item.url = item.FilePath || item.url
                if (item.url.indexOf('.pdf') != -1) {
                    params.pdfurl.value = item.url
                    params.pdfOpen.value = true
                } else {
                    params.imgUrl.value = item.url

                    methods.setVisible(true)
                }
                return
            }

            let item = params.chooseFiles.value.find(es => es.uid == e)
            item.url = item.FilePath || item.url
            if (item.url.indexOf('.pdf') != -1) {
                params.pdfurl.value = item.url
                params.pdfOpen.value = true
            } else {
                params.imgUrl.value = item.url

                methods.setVisible(true)
            }
        },

        btnDownLoad: (e, type) => {
            if (type) {



                let item = params.fileList.value.find(es => es.uid == e)

                console.log(item)
                item.url = item.FilePath || item.url

                const { name, url } = item

                downloadfun(name, url)
                return
            }

            let item = params.chooseFiles.value.find(es => es.uid == e)
            item.url = item.FilePath || item.url

            const { name, url } = item

            downloadfun(name, url )

        },
        btnDelete:async (e, type) => {

       
            if (type) {
                params.chooseFiles.value = params.chooseFiles.value.filter(es => es.uid != e)
                params.lists.value[params.ti.value].NodeList
                [params.i.value].NodeList[params.is.value].NodeList
                [params.iss.value].ItemFileList = params.lists.value[params.ti.value].NodeList
                [params.i.value].NodeList[params.is.value].NodeList
                [params.iss.value].ItemFileList.filter(es => es.uid != e)
                return
            }

     

            let ditem = params.lists.value[params.ti.value].NodeList
            [params.i.value].NodeList[params.is.value].NodeList
            [params.iss.value].ResultItemFileList.filter(es => es.uid == e)[0]


            if (ditem && ditem.FileId) {
                try {
                    let res = await DeleteFormFileItem(Request, ditem.FileId)
                    if (res) {
             
                        params.lists.value[params.ti.value].NodeList
                        [params.i.value].NodeList[params.is.value].NodeList
                        [params.iss.value].ResultItemFileList = params.lists.value[params.ti.value].NodeList
                        [params.i.value].NodeList[params.is.value].NodeList
                        [params.iss.value].ResultItemFileList.filter(es => es.uid != e)



                        if (params.lists.value[params.ti.value].NodeList
                        [params.i.value].NodeList[params.is.value].NodeList
                        [params.iss.value].uploadList = params.lists.value[params.ti.value].NodeList
                        [params.i.value].NodeList[params.is.value].NodeList
                        [params.iss.value].uploadList) {
                            params.lists.value[params.ti.value].NodeList
                            [params.i.value].NodeList[params.is.value].NodeList
                            [params.iss.value].uploadList = params.lists.value[params.ti.value].NodeList
                            [params.i.value].NodeList[params.is.value].NodeList
                            [params.iss.value].uploadList.filter(es => es.uid != e)
                        }

                        params.chooseFiles.value = params.chooseFiles.value.filter(es => es.uid != e)
                    }
                }
                catch (err) {
                    params.messageTest.value.success(err.Msg);

                }
            }

          



        },


        tInput: (e) => {
            console.log(e,'ee')
        },

        tChange: (e) => {
     
            if (e.ItemId) {
                methods.UpdateEvalutionUser(e.ItemId).then(res => {
                    let info = Storage.get('AccountInfo', true)
                    e.EvalutionName = `${info.UserName}(${info.UserNo})`
                })
            } else {
                let info = Storage.get('AccountInfo', true)
                e.EvalutionName = `${info.UserName}(${info.UserNo})`
            }

        },
        planChange: (e) => {

            Request({
                url: "/Performance/GetSelfTempleteByPlan",
                method: 'post',
                params: {
                    Id: e
                }

            }).then(res => {

                params.list.value = res.Data[0].NodeList
                params.TotalScore.value = res.Data[0].TotalScore

            })
        },
        handleFile: (i, is, iss, ess) => {
            params.fileOpen.value = true
            params.i.value=i
            params.is.value = is
            params.iss.value = iss
            params.chooseFiles.value = ess.ItemFileList.map(e => {

                e.url = e.url ? e.url : imageBaseUrl + e.FilePath.split('../..')[1]
                e.FileId = e.FileId
                e.name = e.FileName
                e.isImage = isImageFile(e.url || e.FilePath)
                e.isDelete = false
                return e
            })


        },
        handleFile1: (ti, i, is, iss, ess) => {
            params.fileOpen.value = true
            params.ti.value=ti
            params.i.value = i
            params.is.value = is
            params.iss.value = iss
            params.chooseFiles.value = ess.ResultItemFileList.map(e => {
                return {
                    ...e,
                    FileId: e.FileId,
                    name: e.originFileObj ? e.name : e.FileName,
                    isImage: isImageFile(e.url || e.FilePath),
                    isDelete: !params.urlParams.value.detail
                }
            })

            console.log(params.chooseFiles.value,'22')

        },

        //cwtfbtn() {


        //    params.uploadLock.value = true
        //    html2canvas(document.querySelector("#c0")).then(async (canvas) => {
        //        console.log(canvas)

        //        // 将 canvas 转换为 Blob
        //        const blob = await new Promise((resolve, reject) => {
        //            canvas.toBlob(resolve, 'image/png');
        //        });

        //        // 创建 FormData 对象
        //        const formData = new FormData();
        //        formData.append('file', blob, 'pdf.png');

        //        Request({
        //            url: "/download/uploadfile?Path=toPdf",
        //            method: 'post',
        //            data: formData
        //        }).then(res => {
        //            console.log(res, 'res')
        //            params.uploadLock.value = false
        //        })
        //    });
        //},

        iichange: (i) => {


         
  
            let list = new Set()

            if (params.lists.value[i].NodeList) {
                for (let node of params.lists.value[i].NodeList) {

                    if (node.NodeList) {

                        for (let item of node.NodeList) {

                            if (item.NodeList) {
                                for (let ii of item.NodeList) {
                                    list.add(ii.EvalutionName)
                                }
                            }
                            

                        }
                    }
           
                }
            }

       
            params.lists.value[i].nameList = Array.from(list).filter(Boolean)







            let f = params.lists.value[i].NodeList.map((e, i) => {







                let ff = {

                }
                if (e.CalcType == 0) {
                    if (e.NodeList) {
                        let zz = e.NodeList.map(es => {
                            if (es.NodeList) {
                                let res = es.NodeList.map(ess => {


                                    return ess.ResultScore ? ess.ResultScore : 0
                                })
                                return res.reduce((prev, cur, index, arr) => {
                                    return prev + cur
                                }, 0)
                            }
                        })
                        ff.sub = zz.reduce((prev, cur, index, arr) => {
                            return prev + cur
                        }, 0)
                    }
                } else {
                    if (e.NodeList) {
                        let zz = e.NodeList.map(es => {
                            if (es.NodeList) {
                                let res = es.NodeList.map(ess => {
                                    return ess.ResultScore ? ess.ResultScore : 0
                                })
                                return res.reduce((prev, cur, index, arr) => {
                                    return prev + cur
                                }, 0)
                            }
                        })
                        ff.add = zz.reduce((prev, cur, index, arr) => {
                            return prev + cur
                        }, 0)
                    }
                }

                return ff
            })



            params.lists.value[i].totala = 0
            params.lists.value[i].totals = 0
            params.lists.value[i].TotalScore = params.lists.value[i].TotalScore



            for (let e of f) {
                if (e.add) {
                    params.lists.value[i].totala += e.add
                } else if (e.sub) { params.lists.value[i].totals += e.sub }
            }

            let total = params.lists.value.reduce((acc, item) => acc + item.TotalScore, 0);
            params.totalAmount.value = params.lists.value.reduce((acc, item) => acc + Number(methods.Idealmark(item.TotalScore - (item.totals * params.ScoreRate.value - item.totala).toFixed(2), item.TotalScore)), 0);

            params.totalAmount.value = Number(Number(params.totalAmount.value / total * 100).toFixed(2))

        },
        ichange: (e, ee, ti) => {
      
            if (ee) {


                methods.tChange(ee)
            }
     
            let f = params.lists.value[0].NodeList.map((e, i) => {
                let ff = {

                }
                if (e.CalcType == 0) {
                    if (e.NodeList) {
                        let zz = e.NodeList.map(es => {
                            if (es.NodeList) {
                                let res = es.NodeList.map(ess => {
                                    return ess.SelfScore ? ess.SelfScore : 0
                                })
                                return res.reduce((prev, cur, index, arr) => {
                                    return prev + cur
                                }, 0)
                            }
                        })
                        ff.sub = zz.reduce((prev, cur, index, arr) => {
                            return prev + cur
                        }, 0)
                    }
                } else {
                    if (e.NodeList) {
                        let zz = e.NodeList.map(es => {
                            if (es.NodeList) {
                                let res = es.NodeList.map(ess => {
                                    return ess.SelfScore ? ess.SelfScore : 0
                                })
                                return res.reduce((prev, cur, index, arr) => {
                                    return prev + cur
                                }, 0)
                            }
                        })
                        ff.add = zz.reduce((prev, cur, index, arr) => {
                            return prev + cur
                        }, 0)
                    }
                }

                return ff
            })
            let totala = 0
            let totals = 0


            params.listInfo.value.SelfTotalScore = params.lists.value[0].TotalScore


            for (let e of f) {
                if (e.add) {
                    totala += e.add
                } else if (e.sub) { totals += e.sub }
            }
            params.totala.value = totala
            params.totals.value = totals



            if (typeof ti==='number') {
                methods.iichange(ti)
    
            } else {
   
            }
      
            
        },
        handleDrop: (e) => {
          
        },
        Idealmark: (number,remark,flag=true) => {
            return dealmark(number, flag? remark:null)
        },
        GetDepartmentConfig: (id) => {
            return new Promise((resolve, rej) => {

                Request({
                    url: "/Performance/GetDepartmentConfig",
                    method: 'post',
                    data: {
                        DepartmentId: id
                    }

                }).then(res => {
                    params.ScoreRate.value = res.Data.ScoreRate
                    resolve(1)
                })

            })
        

        },




        UpdateEvalutionUser: (id) => {
            return new Promise((resolve, rej) => {
                Request({
                    url: "performance/UpdateEvalutionUser",
                    method: 'post',
                    params: {
                        ItemId: id,
                    }
                }).then(res => {
                    resolve(1)
                    console.log(res, 'res')

                })
            })

        },
        GetOperateLogList: (id) => {
            return new Promise((resolve, rej) => {
                Request({
                    url: "performance/GetOperateLogList",
                    method: 'post',
                    params: {
                        FormId: id,
                    }
                }).then(res => {

                    params.logList.value = res.Data
                    resolve(1)
                })


            })

      

          
        },
    

        upload: (ti, i, is, iss) => {
            params.ti.value = ti
            params.i.value = i
            params.is.value = is
            params.iss.value = iss

            if (!params.lists.value[params.ti.value].NodeList
            [params.i.value].NodeList[params.is.value].NodeList
            [params.iss.value].ResultItemFileList) {
                params.lists.value[params.ti.value].NodeList
                [params.i.value].NodeList[params.is.value].NodeList
                [params.iss.value].ResultItemFileList = []
            }

        },




        handleCountModelConfirm: () => {
            params.autoSaveParams.value.countdown = params.autoSaveParams.value.ocountdown
            clearInterval(params.autoSaveParams.value.countdownTimer)
            params.autoSaveParams.value.countdownTimer = null
            clearInterval(params.autoSaveParams.value.mainTimer)
            params.autoSaveParams.value.mainTimer = null
            params.autoSaveParams.value.countOpen = false

            methods.onSubmit(0, false).then(res => {
                methods.init()
            })
            methods.startMainTimer()
        },
        handleCountModelClose: () => {
            params.autoSaveParams.value.countdown = params.autoSaveParams.value.ocountdown
            clearInterval(params.autoSaveParams.value.countdownTimer)
            params.autoSaveParams.value.countdownTimer = null
            clearInterval(params.autoSaveParams.value.mainTimer)
            params.autoSaveParams.value.mainTimer = null
            params.autoSaveParams.value.countOpen = false
            methods.startMainTimer()
        },
        startMainTimer: () => {
            if (params.autoSaveParams.value.mainTimer) {
                clearInterval(params.autoSaveParams.value.mainTimer)
                params.autoSaveParams.value.mainTimer=null
            }
            if (params.autoSaveParams.value.countdownTimer) {
                clearInterval(params.autoSaveParams.value.countdownTimer)
                params.autoSaveParams.value.countdownTimer = null
            }


            params.autoSaveParams.value.mainTimer = setInterval(() => {
                params.autoSaveParams.value.countOpen = true
                params.autoSaveParams.value.countdownTimer = setInterval(() => {
                    params.autoSaveParams.value.countdown -= 1
                    if (params.autoSaveParams.value.countdown == 0) {

                        params.autoSaveParams.value.countdown = params.autoSaveParams.value.ocountdown
                        clearInterval(params.autoSaveParams.value.countdownTimer)
                        params.autoSaveParams.value.countdownTimer = null
                        methods.onSubmit(0, false).then(res => {
                            methods.init()
                        })
                        params.autoSaveParams.value.countOpen = false
                    }
                }, 1000)

            }, params.autoSaveParams.value.setIntervalTime)
        },


        mounted: () => {
      
            params.urlParams.value = queryURLParams()
            if (!params.urlParams.value.detail) {
                methods.startMainTimer()
                //document.addEventListener("visibilitychange", function () {
                //    if (document.hidden === true) {
                //        console.log('hidden')
                //        clearInterval(params.autoSaveParams.value.mainTimer)
                //        clearInterval(params.autoSaveParams.value.countdownTimer)
                //        // 页面被挂起
                //    } else {

                //        console.log('show')
                //        methods.startMainTimer()
                //    }
                //});
       
            }

        },





        init: () => {

            getBrowserInfo().catch(err => { console.log(err) })
       
            if (window.localStorage.getItem('pl')) {
                params.autoSaveParams.value.setIntervalTime = +window.localStorage.getItem('pl') * 1000 * 60
            } else {
                window.localStorage.setItem('pl', 5)
                params.autoSaveParams.value.setIntervalTime = 5 * 1000 *60
            }
            if (proxy) {
                params.proxy.value = proxy
            }


            const { message } = antd
            params.messageTest.value = message
            params.messageTest.value.config({
                top: `10vh`,
                duration: 7,
                maxCount: 1,
                rtl: true,
            });

            params.urlParams.value = queryURLParams()

            const { id } = queryURLParams()
            params.mid.value = id
  


            params.uploadLock.value = true

            let info = Storage.get('AccountInfo', true)
            Request({
                url: "/Account/createJwtToken",
                method: 'post',
                data: {
                    "userName": info && info.UserNo
                }
            }).then(res => {
                Storage.set('token', res.Data,true)


                Request({
                    url: "/performance/GetSelfCheckFormEvaluation",
                    method: 'post',
                    params: {
                        FormId:id
                    }
                }).then(async res => {
       
                    params.listInfo.value.DepartmentName = res.Data.DepartmentName
                    params.listInfo.value.UpdateTime = dealTime(res.Data.UpdateTime, 'YYYY-MM-DD HH:mm:ss')
                    params.listInfo.value.UserName = res.Data.UserName
                    params.listInfo.value.UserNo = res.Data.UserNo
                    params.listInfo.value.EvalutionUserList = res.Data.EvalutionUserList||"-"
                   await  methods.GetOperateLogList(params.urlParams.value.id)
           


                    if (params.urlParams.value.detail) {

              

                        if (params.logList.value[1]) {
                            params.checkFrom.value.userName = params.logList.value[1].OperateList.map(e => `${e.OperateUser}`).toString()

                            params.checkFrom.value.subTime = params.logList.value[1].OperateList.filter(e => e.IsApprove).length == 0 ? '-' : dealTime(params.logList.value[1].OperateList.filter(e => e.IsApprove)[params.logList.value[1].OperateList.filter(e => e.IsApprove).length - 1].OperateTime,'YYYY-MM-DD HH:mm:ss')
                        } else {
                            params.checkFrom.value.userName = '-'

                            params.checkFrom.value.subTime = '-'
                        }
     
                      
                    } else {
                        params.checkFrom.value.userName = `${info.UserName}(${info.UserNo})`
                        params.checkFrom.value.subTime = dayjs(Date.now()).format('YYYY-MM-DD HH:mm:ss')
                    }

                    methods.GetDepartmentConfig(res.Data.DepartmentId).then(ress => {
                        params.fileList.value = res.Data.FileList.map(e => {
                            return {
                                ...e,
                                name: e.FileName,
                                url: e.url ? e.url : imageBaseUrl + e.FilePath.split('../..')[1],
                                FileId: e.FileId
                            }
                        })



                        params.lists.value = res.Data.ItemList.map(e => {

                            return {
                                ...e,
                                totala: 0,
                                totals: 0,
                            }
                        })


                        methods.ichange()
                        for (let i = 0; i < params.lists.value.length; i++) {
                            methods.iichange(i)
                        }

                    })



              
                    params.uploadLock.value = false
              
                 
          


                    Request({
                        url: "/performance/GetSimplePlanList",
                        method: 'post',
                        params: {
                            Id: params.urlParams.value.id
                        }
                    }).then(res => {

                
                        params.checkGroup.value = res.Data.map(e => {
                            return {
                                label: e.TeamName,
                                value: e.Id,
                                list: e.MemberList
                            }
                        })

             
                        let item = res.Data.filter(e => e.Id == params.urlParams.value.planid)[0]
                        params.listInfo.value.StartTime = dealTime(item.StartTime, 'YYYY-MM-DD')
                        params.listInfo.value.EndTime = dealTime(item.EndTime, 'YYYY-MM-DD')
                        params.listInfo.value.PlanNoticeName = item.Title
                    })

                    Request({
                        url: "/SystemConfig/GetUserListByDepartment",
                        method: 'post',
                        params: {
                            DepartmentId: res.Data.DepartmentId
                        }
                    }).then(res => {

      
                        params.memberGroup.value = res.Data.map(e => {
                            return {
                                label: `${e.UserName}(${e.UserNo})` ,
                                value: e.UserNo
                            }
                        })
                    })

             


                })





            })

            params.form.value.person = info.UserName
            params.form.value.subdept = info.DepartmentName




            let arry = ['责任', '目标', '风险', '隐患', '培训', '文化', '制度', '应急', '合规', '相关方']
            params.dataSource.value = arry.map(e => {
                return {
                    a: e,
                    b: "",
                    c: ""
                }
            })
  
            const { type } = queryURLParams()
            params.type.value = type

        },
        groupChange: (e) => {


            let item = params.checkGroup.value.find(es => es.value == e)


            params.cmemberGroup1.value = item.list.map(e => {

                return {
                    label: `${e.MemberName}(${e.UserNo})`,

                    value: e.UserNo
                }

            })

            params.s3Form.value.Time = dayjs(Date.now()).format('YYYY-MM-DD HH:mm:ss')

            params.s3Form.value.checkMan = []

        },
        export: (i) => {


       
            params.uploadLock.value = true
            html2canvas(document.querySelector(`#c${i}`)).then(async (canvas) => {

                // 将 canvas 转换为 Blob
                const blob = await new Promise((resolve, reject) => {
                    canvas.toBlob(resolve, 'image/png');
                });

                // 创建 FormData 对象
                const formData = new FormData();
                formData.append('file', blob, 'pdf.png');

                Request({
                    url: "/download/uploadfile?Path=toPdf",
                    method: 'post',
                    data: formData
                }).then(res => {

                    Request({
                        url: `/Performance/ExportPdf?FileId=${res.Data[0].FileId}`,
                        method: 'post',

                    }).then(res => {

                        let name = {
                            0: '通用部分报表',
                            1: '重点工作报表',
                            2: '现场检查报表',
                        }
                        downloadfun(name[i], res.Data)
                        params.uploadLock.value = false

                    })


                })
            });
        },
        groupChange1: (e) => {

            let item = params.checkGroup.value.find(es => es.value == e)

            params.cmemberGroup2.value = item.list.map(e => {
                return {
                    label: `${e.MemberName}(${e.UserNo})`,
                    value: e.UserNo
                }
            })

            params.s4Form.value.Time = dayjs(Date.now()).format('YYYY-MM-DD HH:mm:ss')

            params.s4Form.value.checkMan = []

},

        onSubmit: (Status,isback=true) => {

            return new Promise((resolve, rej) => {

                for (let i = 0; i < params.lists.value.length; i++) {
                    methods.iichange(i)
                }

                let obj = {
                    FormId: params.mid.value,
                    ActualTotalScore: methods.Idealmark(params.listInfo.value.SelfTotalScore - params.totals.value + params.totala.value, params.listInfo.value.SelfTotalScore, false),
                    TotalScore: params.totalAmount.value,
                    IsSave: Status,
                    IsModify: params.urlParams.value.o ? 1 : null,
                    Remark: params.checkFrom.value.advise
                }
                let models = [
                    {
                        FormId: params.mid.value,
                        TypeId: 2,
                        TeamId: params.s3Form.value.group,
                        ApproverList: params.s3Form.value.checkMan && params.s3Form.value.checkMan.toString(),
                        EvaluationDate: params.s3Form.value.Time,
                        CooperatorList: params.s3Form.value.member && params.s3Form.value.member.toString(),
                        Score: params.lists.value.map(e => e.TotalScore)[1],
                        DepartmentManager: params.s3Form.value.duty
                    },
                    {
                        FormId: params.mid.value,
                        TypeId: 3,
                        TeamId: params.s4Form.value.group,
                        ApproverList: params.s4Form.value.checkMan && params.s4Form.value.checkMan.toString(),
                        EvaluationDate: params.s4Form.value.Time,
                        CooperatorList: params.s4Form.value.member && params.s4Form.value.member.toString(),
                        Score: params.lists.value.map(e => e.TotalScore)[2],
                        DepartmentManager: params.s4Form.value.duty
                    }

                ]
                obj.models = models


                let ss = []
                for (let e of params.lists.value) {
                    if (e.NodeList) {
                        e.NodeList.map(es => {
                            if (es.NodeList) {
                                es.NodeList.map(ess => {
                                    if (ess.NodeList) {
                                        ess.NodeList.map(esss => {

                                            esss.ContentId = esss.Id
                                            ss.push(esss)
                                        })
                                    }
                                })
                            }
                        })
                    }

                }

                //if (Status != 0) {
                //    let isNeedFileList = ss.filter(e => e.ResultScore).filter(es => es.CalcType == 1).filter(ess => !ess.ResultItemFileList || ess.ResultItemFileList.length == 0)
                //    if (isNeedFileList.length != 0) {
                //        return params.messageTest.value.info('请上传加分项对应相关证明附件');
                //    }
                //}

                obj.items = ss.map(e => {
                    e.ResultItemFileList = e.uploadList ? e.uploadList.filter(es => es.lastModified) : []
                    return e
                })

                Request({
                    url: "/performance/AddEvaluationForm",
                    method: 'post',
                    data: obj
                }).then(res => {
                    if (isback) {
                        params.messageTest.value.success(res.Msg);
                        setTimeout(() => {
                            methods.onBack()
                        }, 1500)
                    } else {
                        params.messageTest.value.success('自动保存成功');
                    }
                    resolve(1)
                })
            })

       

     

        },
        onBack: () => {
            window.close()
        }


    }
    const template = {
        countModel: {
            template: `
            <a-modal v-model:open="autoSaveParams.countOpen" ok-text="立即保存" title="自动保存" v-on:cancel="handleCountModelClose" v-on:ok="handleCountModelConfirm">
                <div style='height:auto;font-size:14px'>
                    {{autoSaveParams.countdown}}秒后自动保存,如果您正在操作，请点击取消
                </div>
        </a-modal>
`,
            setup() {
                return {
                    ...params,
                    ...methods,
                };
            }
        },
        pdfPopModel: {
            template: `
           <a-modal v-model:open="pdfOpen" width = "80%" title = "PDF预览" v-on:ok="pdfOpen=false" >
<div style='height:700px'>
                <embed id="pdfviewscreen" :src="pdfurl" type="application/pdf" width="100%" style="height:100%;" />

</div>
  
            </a-modal >
`,
            setup() {
                return {
                    ...params,
                    ...methods,
                };
            }
        },


        popModel: {
            template: `
        <a-modal v-model:open="textPopOpen" width="60%" title="考评情况/资料说明" ok-text="保存" v-on:ok="fillText">
                <div style="padding:30px;box-sizing:border-box">
                    <a-textarea v-model:value="fillTextValue" placeholder="考评情况/资料说明"  :auto-size="{ minRows: 16, maxRows: 25 }" />
                </div>
            </a-modal>
`,
            setup() {

                return {
                    ...params,
                    ...methods,
                };
            }
        },
        bottomBtns: {
            template: `<div class="w-full bg-[#eeeeee] h-50  flex  items-center justify-end">
                    <a-space>

  <a-popconfirm
    title="确定执行此操作?"
    ok-text="确定"
    cancel-text="取消"
    @confirm="onSubmit(0)"
  >


       <a-button v-if="!urlParams.detail" :loading="uploadLock" type="primary">保存</a-button>
  </a-popconfirm>


  <a-popconfirm
    title="确定执行此操作?"
    ok-text="确定"
    cancel-text="取消"
    @confirm="onSubmit(1)"
  >


         <a-button v-if="!urlParams.detail&&!urlParams.o" :loading="uploadLock"  type="primary">提交{{urlParams.o}}</a-button>
  </a-popconfirm>

                 
               
                        <a-button v-on:click="onBack">返回</a-button>
  


                    </a-space>
                </div>`,
            setup() {

                return {
                    ...params,
                    ...methods,
                };
            }

        }
    }


    //let template = toRefs(vtemplate)
    return { // 返回对象给模板

        ...params,
        ...methods,
        template

    }
}


export default Composition